Skip to content

Conversation

@darwin808
Copy link
Contributor

@darwin808 darwin808 commented Dec 31, 2025

Summary

  • Auto-enforces Secure=true when Partitioned=true is set on a cookie, per the CHIPS specification
  • Updates cookie expiration documentation to use fasthttp.CookieExpireDelete constant
  • Adds documentation example for expiring cookies with Path/Domain attributes

Changes

Cookie enforcement (res.go):

  • Automatically sets Secure=true when a cookie has Partitioned=true, as required by the CHIPS
    spec

Documentation (docs/api/ctx.md):

  • Uses fasthttp.CookieExpireDelete instead of manual time calculation for cookie deletion examples
  • Adds example showing how to expire cookies with specific Path/Domain attributes

Test plan

  • Updated test to reflect auto-fix behavior for Partitioned cookies
  • All existing cookie tests pass

Fixes #2878

@darwin808 darwin808 requested a review from a team as a code owner December 31, 2025 05:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Documentation updates to the Fiber context API showing proper cookie expiration using fasthttp.CookieExpireDelete constant instead of manual time calculations, including a new example with Path and Domain attributes.

Changes

Cohort / File(s) Summary
Cookie deletion documentation
docs/api/ctx.md
Replaces manual expiration calculation (time.Now().Add(-(time.Hour * 2))) with fasthttp.CookieExpireDelete constant in delete example; adds new example demonstrating cookie expiration with Path and Domain attributes

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

codex

Suggested reviewers

  • gaby
  • sixcolors
  • ReneWerner87
  • efectn

Poem

🐰 Cookies were tricky, expiring with fuss,
But CookieExpireDelete saves all of us!
No more time math, just constants so clean,
The sweetest docs we've ever seen! 🍪✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The pull request title mentions auto-enforcing Secure=true for Partitioned cookies, but the actual changes only involve updating cookie expiration examples in documentation with no implementation of this feature. Update the title to accurately reflect the actual changes: e.g., 'docs: Update cookie expiration examples to use fasthttp.CookieExpireDelete' or align implementation with the title by adding the Secure=true auto-enforcement feature.
Out of Scope Changes check ❓ Inconclusive The raw summary shows only documentation updates to docs/api/ctx.md without API implementation details, making it unclear if out-of-scope changes exist in the complete changeset. Provide the complete file change summary including implementation files (ctx.go or response.go) to verify all changes align with the ExpireCookie feature objective.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses the core objective from #2878 by providing ExpireCookie() to expire cookies with Path/Domain/Secure/HTTPOnly attributes, enabling proper browser-side deletion matching the RFC 6265 requirement.
Description check ✅ Passed The PR description is well-structured with a clear summary, detailed changes section, and completed test plan, addressing the repository's template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @darwin808, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the framework's cookie management capabilities by introducing a dedicated ExpireCookie method. This new functionality resolves a long-standing issue where the ClearCookie method was unable to properly expire cookies that were initially set with specific Path or Domain attributes, a common requirement for secure and precise cookie handling. By allowing the explicit specification of these attributes during expiration, the framework now fully complies with browser standards, providing developers with a more robust and intuitive way to manage client-side cookies.

Highlights

  • New ExpireCookie Method: Introduced a new ExpireCookie(cookie Cookie) method to correctly expire cookies that were set with specific Path or Domain attributes, addressing a limitation of the existing ClearCookie method.
  • Enhanced Cookie Expiration: The new method allows specifying Name, Path, Domain, Secure, and HTTPOnly attributes, ensuring proper cookie expiration according to RFC 6265 requirements.
  • Updated ClearCookie Documentation: The documentation for ClearCookie has been updated to explicitly note its limitation with cookies that have specific Path or Domain attributes, guiding users to the new ExpireCookie method for such cases.
  • Comprehensive Unit Tests: Added extensive unit tests for ExpireCookie covering various attribute combinations (path, domain, secure, httponly) to ensure its reliability and correctness.
  • API Documentation and Examples: The API documentation (docs/api/ctx.md) has been updated with detailed explanations, signature, and practical examples for the new ExpireCookie method, including a comparison to the previous workaround.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ReneWerner87 ReneWerner87 added this to the v3 milestone Dec 31, 2025
@ReneWerner87 ReneWerner87 added this to v3 Dec 31, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new ExpireCookie method to correctly expire cookies with specific Path or Domain attributes, addressing a limitation in the existing ClearCookie method. The implementation is a good start, but it's missing support for SameSite and Partitioned attributes, which are crucial for expiring modern cookies correctly. I've provided suggestions to add this functionality, update the corresponding documentation, and enhance the unit tests for better coverage and maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
ctx_test.go (1)

4506-4562: Solid coverage for ExpireCookie; consider a couple of small assertions

The test exercises the important combinations (Path, Domain, Path+Domain, Secure+HttpOnly) and verifies the Set-Cookie line in a robust, order‑independent way. Two optional tightenings you might consider:

  • Also assert require.Contains(t, setCookie, "expires=") in the Domain and Path+Domain (and possibly Secure+HttpOnly) cases, so every variant explicitly checks that the cookie is actually expired, not just that attributes are present.
  • Optionally add a single scenario that calls c.ExpireCookie(...) instead of c.Res().ExpireCookie(...) to exercise the Ctx helper as well as the Res method.

Using Response().Header.Peek(HeaderSetCookie) with string matching is consistent with the established pattern of manually inspecting Set-Cookie in Fiber tests, instead of relying on Header.Cookie. Based on learnings, ...

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 789c56f and 2a2f69c.

📒 Files selected for processing (5)
  • ctx_interface_gen.go
  • ctx_test.go
  • docs/api/ctx.md
  • res.go
  • res_interface_gen.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Prefer github.com/gofiber/utils/v2 helpers (for example, utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code

Files:

  • ctx_interface_gen.go
  • res.go
  • ctx_test.go
  • res_interface_gen.go
docs/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Review and update the contents of the docs folder if necessary when modifying code

Files:

  • docs/api/ctx.md
**/*.md

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Run make markdown to lint all Markdown files when modifying code

Files:

  • docs/api/ctx.md
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

When adding Go tests, always invoke t.Parallel() at the start of each test and subtest to maximize concurrency

Files:

  • ctx_test.go
🧠 Learnings (8)
📓 Common learnings
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
📚 Learning: 2024-09-25T15:57:10.221Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.

Applied to files:

  • ctx_interface_gen.go
  • res.go
  • docs/api/ctx.md
  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-01T03:33:22.283Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-12T10:01:44.206Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session `IdleTimeout` expiration, it's acceptable to use `time.Sleep` to simulate the passage of time in tests.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-11-29T12:37:27.581Z
Learnt from: efectn
Repo: gofiber/fiber PR: 3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the `Test_App_ShutdownWithContext` function in `app_test.go`, the `clientDone` channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional `time.Sleep` calls.

Applied to files:

  • ctx_test.go
🧬 Code graph analysis (2)
ctx_interface_gen.go (3)
res.go (1)
  • Cookie (104-116)
client/request.go (1)
  • Cookie (778-778)
bind_test.go (2)
  • Cookie (1512-1516)
  • Cookie (1757-1761)
ctx_test.go (3)
res_interface_gen.go (1)
  • Res (13-174)
res.go (1)
  • Cookie (104-116)
constants.go (1)
  • HeaderSetCookie (197-197)
🔇 Additional comments (5)
res_interface_gen.go (1)

21-34: ClearCookie note and ExpireCookie API look consistent and clear

The new documentation accurately scopes ClearCookie’s limitations and positions ExpireCookie as the attribute-aware alternative; the ExpireCookie signature is minimal and consistent with the Cookie struct fields.

ctx_interface_gen.go (1)

327-340: Ctx-level ExpireCookie matches Res API and clarifies ClearCookie behavior

Adding ExpireCookie to Ctx with matching docs keeps the public surface coherent and clearly directs users away from ClearCookie for Domain/Path-specific cookies.

docs/api/ctx.md (2)

1743-1774: LGTM! Clear documentation of ClearCookie limitations.

The updated caution note and reference to ExpireCookie provide excellent guidance for developers who need to clear cookies with specific Path or Domain attributes.


1775-1813: LGTM! Comprehensive and well-structured documentation.

The ExpireCookie documentation is excellent:

  • Clear method signature and description
  • Practical examples covering common scenarios
  • Important note about which Cookie fields are actually used

This will help developers properly expire cookies with Path/Domain attributes.

res.go (1)

202-219: LGTM! Documentation accurately reflects the limitation.

The updated ClearCookie documentation correctly notes that it cannot clear cookies with specific Path or Domain attributes, and appropriately directs users to ExpireCookie for those cases.

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.24%. Comparing base (dd25c72) to head (338dad1).
⚠️ Report is 60 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3976      +/-   ##
==========================================
+ Coverage   91.03%   91.24%   +0.21%     
==========================================
  Files         119      119              
  Lines       10870    11050     +180     
==========================================
+ Hits         9895    10083     +188     
+ Misses        617      613       -4     
+ Partials      358      354       -4     
Flag Coverage Δ
unittests 91.24% <100.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@darwin808 darwin808 force-pushed the fix/expire-cookie-path-domain branch from 2a2f69c to cf04f3f Compare December 31, 2025 05:28
@darwin808
Copy link
Contributor Author

The CI failure in Test_App_Test_Goroutine_Leak_Compare is unrelated to this PR's changes. This test checks goroutine leak behavior in app.Test() and is sensitive to system load/timing during CI runs.

The test expected <10 leaked goroutines but got 14, which can vary based on:

  • Concurrent test execution
  • GC timing
  • System background processes

Could a maintainer please re-run CI? The ExpireCookie changes only affect cookie handling and don't touch the app.Test() code path.

@gaby
Copy link
Member

gaby commented Dec 31, 2025

@darwin808 Don't use force push, we can't see what's changing between commits. Makes reviewing harder.

@gaby
Copy link
Member

gaby commented Dec 31, 2025

@darwin808 Tag me once the comments raised as addressed. Thanks 💪

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/api/ctx.md (1)

1806-1810: Consider using the typed constant in documentation for consistency.

The example uses the string literal "Strict" which works correctly due to case-insensitive matching. For documentation clarity, you might consider showing the constant usage alongside the string literal, since users might import and use fiber.CookieSameSiteStrictMode.

// Using the constant:
c.Res().ExpireCookie(&fiber.Cookie{
    Name:     "csrf",
    SameSite: fiber.CookieSameSiteStrictMode,
})

This is a minor suggestion for consistency with how the codebase defines these values.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf04f3f and c715d6a.

📒 Files selected for processing (5)
  • ctx_interface_gen.go
  • ctx_test.go
  • docs/api/ctx.md
  • res.go
  • res_interface_gen.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • res_interface_gen.go
  • ctx_test.go
🧰 Additional context used
📓 Path-based instructions (3)
docs/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Review and update the contents of the docs folder if necessary when modifying code

Files:

  • docs/api/ctx.md
**/*.md

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Run make markdown to lint all Markdown files when modifying code

Files:

  • docs/api/ctx.md
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Prefer github.com/gofiber/utils/v2 helpers (for example, utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code

Files:

  • ctx_interface_gen.go
  • res.go
🧠 Learnings (3)
📓 Common learnings
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
📚 Learning: 2024-09-25T15:57:10.221Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.

Applied to files:

  • docs/api/ctx.md
  • res.go
📚 Learning: 2025-07-19T14:06:29.884Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".

Applied to files:

  • docs/api/ctx.md
  • ctx_interface_gen.go
  • res.go
🧬 Code graph analysis (2)
ctx_interface_gen.go (2)
res.go (1)
  • Cookie (104-116)
client/request.go (1)
  • Cookie (778-778)
res.go (3)
bind_test.go (2)
  • Cookie (1512-1516)
  • Cookie (1757-1761)
constants.go (3)
  • CookieSameSiteStrictMode (315-315)
  • CookieSameSiteNoneMode (316-316)
  • CookieSameSiteLaxMode (314-314)
client/response.go (1)
  • Response (19-25)
🔇 Additional comments (4)
res.go (2)

204-206: LGTM!

Clear documentation update that properly warns users about the ClearCookie limitation for cookies with Domain/Path attributes and directs them to use ExpireCookie.


221-265: Well-implemented cookie expiration with full attribute support.

The implementation correctly handles:

  • Path and Domain matching for proper cookie deletion per RFC 6265
  • SameSite attribute with case-insensitive comparison
  • Partitioned cookies (CHIPS)
  • Auto-enforcement of Secure=true when SameSite=None or Partitioned=true per browser requirements

The Acquire/Release pattern for fasthttp cookies is correctly used, and the deferred release ensures cleanup.

ctx_interface_gen.go (1)

329-340: LGTM!

The interface definition correctly mirrors the implementation. The documentation properly notes all fields used (Name, Path, Domain, Secure, HTTPOnly, SameSite, Partitioned) and clarifies that Value/Expires are overwritten.

docs/api/ctx.md (1)

1773-1824: Comprehensive documentation for the new ExpireCookie API.

The examples effectively demonstrate all supported use cases:

  • Path-specific cookies
  • Domain-specific cookies
  • Security flags (Secure, HTTPOnly)
  • SameSite attribute
  • Partitioned cookies (CHIPS)

The note block clearly explains which fields are consumed and that Value/Expires are overwritten.

@darwin808
Copy link
Contributor Author

@gaby Addressed the review comments - added SameSite and Partitioned support, updated docs, and refactored tests to table-driven style.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
ctx_test.go (1)

4506-4598: Solid ExpireCookie coverage; consider releasing acquired contexts.

The table‑driven test nicely exercises Path/Domain, SameSite variants, Secure/HTTPOnly, and Partitioned behavior with parallel subtests, which aligns well with the new API.

Minor nit: each subtest calls app.AcquireCtx(&fasthttp.RequestCtx{}) but never releases the context. For consistency with other tests and better pool hygiene, consider:

Suggested cleanup
-			app := New()
-			c := app.AcquireCtx(&fasthttp.RequestCtx{})
+			app := New()
+			c := app.AcquireCtx(&fasthttp.RequestCtx{})
+			defer app.ReleaseCtx(c)
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c715d6a and 48bf4ad.

📒 Files selected for processing (2)
  • ctx_test.go
  • res.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Prefer github.com/gofiber/utils/v2 helpers (for example, utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code

Files:

  • res.go
  • ctx_test.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

When adding Go tests, always invoke t.Parallel() at the start of each test and subtest to maximize concurrency

Files:

  • ctx_test.go
🧠 Learnings (9)
📓 Common learnings
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
📚 Learning: 2025-07-19T14:06:29.884Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".

Applied to files:

  • res.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.

Applied to files:

  • res.go
  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-01T03:33:22.283Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.

Applied to files:

  • ctx_test.go
📚 Learning: 2025-12-07T15:07:23.885Z
Learnt from: CR
Repo: gofiber/fiber PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-07T15:07:23.885Z
Learning: Applies to **/*_test.go : When adding Go tests, always invoke `t.Parallel()` at the start of each test and subtest to maximize concurrency

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-12T10:01:44.206Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session `IdleTimeout` expiration, it's acceptable to use `time.Sleep` to simulate the passage of time in tests.

Applied to files:

  • ctx_test.go
🧬 Code graph analysis (1)
ctx_test.go (3)
res.go (1)
  • Cookie (104-116)
constants.go (3)
  • CookieSameSiteStrictMode (315-315)
  • CookieSameSiteLaxMode (314-314)
  • CookieSameSiteNoneMode (316-316)
res_interface_gen.go (1)
  • Res (13-174)
🔇 Additional comments (1)
res.go (1)

202-207: ExpireCookie implementation and docs align with the intended semantics.

The ClearCookie comment accurately documents its Path/Domain limitation, and DefaultRes.ExpireCookie correctly:

  • Constructs a deletion cookie ("" value, CookieExpireDelete).
  • Mirrors Path/Domain, when provided.
  • Applies SameSite via case‑insensitive compare, and forces Secure for SameSite=None and Partitioned cookies.
  • Preserves/overrides only the documented fields and emits the header via SetCookie.

This matches the new Res/Ctx interface contract and the RFC/best‑practice requirements around SameSite=None and partitioned cookies. I don’t see further changes needed here.

Also applies to: 221-267

@darwin808 darwin808 requested a review from gaby January 2, 2026 04:32
@ReneWerner87
Copy link
Member

@darwin808 can you check my hint

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an ExpireCookie method to properly expire cookies that were set with specific Path or Domain attributes, addressing a limitation in the existing ClearCookie method which uses fasthttp.DelClientCookie that doesn't support these attributes.

Changes:

  • Added ExpireCookie(cookie *Cookie) method to DefaultRes that respects Path, Domain, and security attributes when expiring cookies
  • Updated ClearCookie documentation to clarify its limitations with Path/Domain cookies
  • Added automatic Secure=true handling for Partitioned cookies in the Cookie method to comply with CHIPS spec

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
res_interface_gen.go Added ExpireCookie interface method with documentation noting Path/Domain support
ctx_interface_gen.go Added ExpireCookie interface method to Ctx interface
res.go Implemented ExpireCookie method with proper attribute handling and updated Cookie method for Partitioned cookies
ctx_test.go Added comprehensive test cases for ExpireCookie covering path, domain, security flags, SameSite, and Partitioned attributes
docs/api/ctx.md Added documentation and examples for ExpireCookie usage, added note to ClearCookie about its limitations

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @ctx_test.go:
- Around line 4548-4654: The subtests in Test_Ctx_ExpireCookie capture the loop
variable tc while running in parallel and also pass the table's Cookie value by
reference into ExpireCookie which mutates it; fix by shadowing the loop variable
(add "tc := tc" at the start of the t.Run closure) and pass a local copy of the
cookie to ExpireCookie (e.g., "cookieCopy := tc.cookie" then call
"c.Res().ExpireCookie(&cookieCopy)") so the shared table entry isn't mutated
across parallel subtests.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efcc881 and fbfdd73.

📒 Files selected for processing (3)
  • ctx_test.go
  • docs/api/ctx.md
  • res.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • res.go
  • docs/api/ctx.md
🧰 Additional context used
📓 Path-based instructions (2)
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

When adding Go tests, always invoke t.Parallel() at the start of each test and subtest to maximize concurrency

Files:

  • ctx_test.go
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Prefer github.com/gofiber/utils/v2 helpers (for example, utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code

Files:

  • ctx_test.go
🧠 Learnings (9)
📓 Common learnings
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-10-08T19:06:06.583Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-01T03:44:03.672Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-09-25T15:57:10.221Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-01T03:33:22.283Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3051
File: middleware/session/session.go:215-216
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.

Applied to files:

  • ctx_test.go
📚 Learning: 2025-12-07T15:07:23.885Z
Learnt from: CR
Repo: gofiber/fiber PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-07T15:07:23.885Z
Learning: Applies to **/*_test.go : When adding Go tests, always invoke `t.Parallel()` at the start of each test and subtest to maximize concurrency

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-16T12:12:30.506Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3170
File: ctx_test.go:1721-1724
Timestamp: 2024-10-16T12:12:30.506Z
Learning: In the Go unit tests in `ctx_test.go`, it is acceptable to use invalid CIDR notation such as `"0.0.0.1/31junk"` for testing purposes.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-12T10:01:44.206Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/session/middleware_test.go:190-191
Timestamp: 2024-10-12T10:01:44.206Z
Learning: When testing session `IdleTimeout` expiration, it's acceptable to use `time.Sleep` to simulate the passage of time in tests.

Applied to files:

  • ctx_test.go
🧬 Code graph analysis (1)
ctx_test.go (3)
res.go (1)
  • Cookie (104-116)
constants.go (4)
  • CookieSameSiteStrictMode (315-315)
  • CookieSameSiteLaxMode (314-314)
  • CookieSameSiteNoneMode (316-316)
  • CookieSameSiteDisabled (313-313)
res_interface_gen.go (1)
  • Res (13-174)
🔇 Additional comments (1)
ctx_test.go (1)

1214-1215: Good clarification on Partitioned+Secure auto-fix.

This comment helps explain why the Partitioned-invalid test case is gone and documents the intended behavior.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
ctx_test.go (3)

2483-2513: Release acquired ctx in Test_Ctx_IP_ProxyHeader (avoid leaks across table loop).
Each loop iteration calls app.AcquireCtx(...) but never app.ReleaseCtx(...).

Proposed fix
 	for _, proxyHeaderName := range proxyHeaderNames {
 		app := New(Config{ProxyHeader: proxyHeaderName})
 		c := app.AcquireCtx(&fasthttp.RequestCtx{})
+		defer app.ReleaseCtx(c)

 		c.Request().Header.Set(proxyHeaderName, "0.0.0.1")
 		require.Equal(t, "0.0.0.1", c.IP())
@@
 		c.Request().Header.Set(proxyHeaderName, "not-valid-ip")
 		require.Equal(t, "not-valid-ip", c.IP())
 	}

Note: if you keep the defer inside the loop, it defers until the test ends (still correct, but less ideal). Prefer t.Run(...) subtests with defer/t.Cleanup, or explicitly app.ReleaseCtx(c) at loop end.


2516-2546: Release acquired ctx in Test_Ctx_IP_ProxyHeader_With_IP_Validation (avoid leaks).
Same issue as the non-validation variant.

Proposed fix
 	for _, proxyHeaderName := range proxyHeaderNames {
 		app := New(Config{EnableIPValidation: true, ProxyHeader: proxyHeaderName})
 		c := app.AcquireCtx(&fasthttp.RequestCtx{})
+		defer app.ReleaseCtx(c)

 		// when proxy header & validation is enabled and the value is a valid IP, we return it
 		c.Request().Header.Set(proxyHeaderName, "0.0.0.1")
 		require.Equal(t, "0.0.0.1", c.IP())
@@
 		c.Request().Header.Set(proxyHeaderName, "not-valid-ip")
 		require.Equal(t, "0.0.0.0", c.IP())
 	}

Same note re: defer in a loop; t.Run + t.Cleanup is usually cleaner here.


3386-3419: Test_Ctx_Scheme: add t.Parallel() + release acquired ctx.
This test currently (a) doesn’t call t.Parallel() and (b) doesn’t release the acquired ctx.

Proposed fix
 func Test_Ctx_Scheme(t *testing.T) {
+	t.Parallel()
 	app := New()

 	freq := &fasthttp.RequestCtx{}
 	freq.Request.Header.Set("X-Forwarded", "invalid")

 	c := app.AcquireCtx(freq)
+	defer app.ReleaseCtx(c)

As per coding guidelines, tests should call t.Parallel() at the start.

♻️ Duplicate comments (1)
ctx_test.go (1)

2226-2340: Fix missing ctx release in Test_Ctx_IsProxyTrusted (pool leak / flake risk).
Second scenario (Lines 2239-2241) acquires a ctx but never releases it.

Proposed fix
 	{
 		app := New(Config{
 			TrustProxy: false,
 		})
 		c := app.AcquireCtx(&fasthttp.RequestCtx{})
+		defer app.ReleaseCtx(c)
 		require.True(t, c.IsProxyTrusted())
 	}
🧹 Nitpick comments (1)
ctx_interface_gen.go (1)

315-318: Tighten IsProxyTrusted doc wording/grammar (avoid ambiguity).

Consider rephrasing Line 316 to be grammatical and explicit (e.g., “If Config.TrustProxy is false, it returns true.”) and add a trailing period.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbfdd73 and 2375d3e.

📒 Files selected for processing (3)
  • ctx_interface_gen.go
  • ctx_test.go
  • docs/api/ctx.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/api/ctx.md
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Prefer github.com/gofiber/utils/v2 helpers (for example, utils.Trim) when performing common operations such as string manipulation, whenever it is practical and appropriate for the surrounding code

Files:

  • ctx_interface_gen.go
  • ctx_test.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

When adding Go tests, always invoke t.Parallel() at the start of each test and subtest to maximize concurrency

Files:

  • ctx_test.go
🧠 Learnings (13)
📓 Common learnings
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.
📚 Learning: 2024-10-16T14:00:50.724Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3170
File: ctx.go:1825-1826
Timestamp: 2024-10-16T14:00:50.724Z
Learning: In the Fiber framework, the `IsProxyTrusted()` function returns `true` when `TrustProxy` is `false`, maintaining compatibility with version 2 behavior.

Applied to files:

  • ctx_interface_gen.go
  • ctx_test.go
📚 Learning: 2025-07-19T14:06:29.884Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3598
File: docs/middleware/csrf.md:37-42
Timestamp: 2025-07-19T14:06:29.884Z
Learning: In Fiber v3, the CookieSameSite constants use lowercase values: CookieSameSiteLaxMode = "lax", CookieSameSiteStrictMode = "strict", CookieSameSiteNoneMode = "none". Documentation examples should use lowercase string values or the typed constants, not capitalized strings like "Lax".

Applied to files:

  • ctx_interface_gen.go
📚 Learning: 2024-09-25T15:57:10.221Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/csrf/csrf_test.go:188-193
Timestamp: 2024-09-25T15:57:10.221Z
Learning: In the Fiber framework tests, using `ctx.Response.Header.Cookie` may not be suitable for parsing cookies from the response header, as it requires a `*Cookie` and fills it rather than returning a string value; thus, manual parsing of the `Set-Cookie` header may be necessary.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-06-30T00:38:06.580Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3051
File: middleware/session/session.go:215-216
Timestamp: 2024-06-30T00:38:06.580Z
Learning: Parallel tests for `Session.Save` already exist in the `middleware/session/session_test.go` file, specifically in the `Test_Session_Save` and `Test_Session_Save_Expiration` functions.

Applied to files:

  • ctx_test.go
📚 Learning: 2025-12-07T15:07:23.885Z
Learnt from: CR
Repo: gofiber/fiber PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-07T15:07:23.885Z
Learning: Applies to **/*_test.go : When adding Go tests, always invoke `t.Parallel()` at the start of each test and subtest to maximize concurrency

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-02T13:29:56.992Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-10-08T19:06:06.583Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-07-01T03:33:22.283Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-09-25T17:09:03.756Z
Learnt from: sixcolors
Repo: gofiber/fiber PR: 3016
File: middleware/session/middleware_test.go:400-407
Timestamp: 2024-09-25T17:09:03.756Z
Learning: In the `Test_Session_Next` function in `middleware/session/middleware_test.go`, the variable `doNext` is properly synchronized with the `muNext` mutex for both read and write access.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-11-10T23:44:13.704Z
Learnt from: gaby
Repo: gofiber/fiber PR: 3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.

Applied to files:

  • ctx_test.go
📚 Learning: 2024-11-29T12:37:27.581Z
Learnt from: efectn
Repo: gofiber/fiber PR: 3162
File: app_test.go:893-895
Timestamp: 2024-11-29T12:37:27.581Z
Learning: In the `Test_App_ShutdownWithContext` function in `app_test.go`, the `clientDone` channel is used to synchronize the client's request completion before proceeding, eliminating the need for additional `time.Sleep` calls.

Applied to files:

  • ctx_test.go
📚 Learning: 2025-10-16T07:19:52.418Z
Learnt from: grivera64
Repo: gofiber/fiber PR: 3807
File: adapter_test.go:118-144
Timestamp: 2025-10-16T07:19:52.418Z
Learning: In the Fiber codebase, the linter does not allow `require` assertions from within HTTP handlers (including net/http-style handlers). Use `t.Fatalf`, `t.Errorf`, or similar `testing.T` methods for error handling inside handler functions instead.

Applied to files:

  • ctx_test.go
🔇 Additional comments (1)
ctx_test.go (1)

2698-2720: Benchmark config change looks fine.
Setting ProxyHeader in the benchmark setup matches the new test configuration style.

Fixes gofiber#2878

ClearCookie() does not work for cookies that were set with specific
Path or Domain attributes because browsers require matching attributes
to properly clear a cookie.

This adds ExpireCookie(cookie Cookie) which allows specifying the Path,
Domain, Secure, and HTTPOnly attributes when expiring a cookie, ensuring
the browser properly matches and clears it.
- Handle SameSite attribute (Strict/Lax/None) for proper cookie expiration
- Handle Partitioned attribute for CHIPS cookies
- Auto-set Secure=true when SameSite=None or Partitioned=true (per RFC)
- Update documentation with new examples
- Refactor tests to table-driven style with comprehensive coverage
- Add default case to SameSite switch statement (revive)
- Reorder struct fields for better memory alignment (govet)
- Add defer app.ReleaseCtx(c) for proper context cleanup
- Reorder struct fields for optimal memory alignment
- Add Secure enforcement for Partitioned cookies per CHIPS spec
- Update test to reflect new auto-fix behavior
- Add CookieSameSiteDisabled handling in ExpireCookie to not set
  SameSite attribute when explicitly disabled
- Fix documentation signature to show fiber.Res receiver instead of
  fiber.Ctx
- Add test case for CookieSameSiteDisabled to verify SameSite is not
  present in Set-Cookie header
Remove ExpireCookie method - the existing Cookie() method handles this
use case by setting Expires to fasthttp.CookieExpireDelete.

Updated documentation to show the recommended approach.

Fixes gofiber#2878
@darwin808 darwin808 force-pushed the fix/expire-cookie-path-domain branch from 2375d3e to 2e985d2 Compare January 14, 2026 00:41
@ReneWerner87
Copy link
Member

@darwin808 thx for the adjustments

I checked and now only documentation adjustments are included.
Can you change the description and headline for this?
I also think the addition you wanted to add regarding “cookie.Partitioned” is still missing.
In your original method, you had an auto change for this, right?

@ReneWerner87
Copy link
Member

i mean this
#3976 (comment)
ab2fd70

@ReneWerner87
Copy link
Member

@darwin808 ping
we only need this last small adjustment

- Add Secure enforcement for Partitioned cookies per CHIPS spec
- Update test to reflect new auto-fix behavior
@darwin808 darwin808 changed the title 🔥 feat: Add ExpireCookie method for cookies with Path/Domain feat: Auto-enforce Secure=true for Partitioned cookies in Cookie() Jan 21, 2026
@darwin808 darwin808 changed the title feat: Auto-enforce Secure=true for Partitioned cookies in Cookie() 🔥 feat: Auto-enforce Secure=true for Partitioned cookies in Cookie() Jan 21, 2026
@darwin808
Copy link
Contributor Author

@ReneWerner87 Done! Added the Partitioned → Secure=true auto-enforcement in 338dad1 and updated the PR title/description. Ready for review.

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 merged commit cfac76d into gofiber:main Jan 21, 2026
21 checks passed
@welcome
Copy link

welcome bot commented Jan 21, 2026

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@github-project-automation github-project-automation bot moved this to Done in v3 Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: (c *fiber.Ctx).ClearCookie() does absolutely nothing

3 participants